//
//  DHAddCommentViewController.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/1/9.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHAddCommentViewController.h"
#import "PlaceholderTextView.h"

@interface DHAddCommentViewController ()

@property (weak, nonatomic) IBOutlet PlaceholderTextView *textView;
@property (strong, nonatomic) NSString *articleID;

@end

@implementation DHAddCommentViewController

- (instancetype)initWithArticleID:(NSString *)articleID
{
    self = [super init];
    if (self) {
        self.articleID = articleID;
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.textView becomeFirstResponder];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleLabel.text = @"发表评论";
    self.view.backgroundColor = [UIColor whiteColor];
    self.textView.placeholder = @"请在次数留下您的评论…";
    
    UIButton *doneButton = [[UIButton alloc] initWithFrame:CGRectMake(self.navView.width - 64, self.navView.height - 44, 54, 44)];
    [doneButton setTitle:@"发表" forState:UIControlStateNormal];
    doneButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [doneButton setTitleColor:[UIColor colorWithHexString:@"#4a4a4a"] forState:UIControlStateNormal];
    [self.navView addSubview:doneButton];
    
    WeakSelf(weakSelf)
    [doneButton bk_addEventHandler:^(id sender) {
        if (weakSelf.textView.text.length > 0) {
            [[DHNetAPIClient shareDHNetAPIClient] request_articles_commentWithArticleID:weakSelf.articleID content:weakSelf.textView.text andBlock:^(id data, NSError *error) {
                [weakSelf.navigationController popViewControllerAnimated:YES];
            }];
        }else{
            [NSObject showHudTipStr:@"请输入评论"];
        }
    } forControlEvents:UIControlEventTouchUpInside];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
